package edu.controller;




import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import edu.domain.GoodsCollect;
import edu.service.GoodsCollectService;
import edu.support.base.controller.AdminBaseController;
import edu.support.base.BasePage;
import edu.support.mybatis.MybatisWrapper;
import edu.support.resp.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * (GoodsCollect)表控制层
 *
 * @date  20:03:45
 */

@Controller
@RequestMapping("goodsCollect")
public class GoodsCollectController extends AdminBaseController {

    @Autowired
    private GoodsCollectService goodsCollectService;

    /**
     * 列表
     *
     * @param model
     * @param goodsCollect
     * @return
     */
    @RequestMapping("list")
    public String list(Model model, GoodsCollect goodsCollect, BasePage rowPage) {
        QueryWrapper<GoodsCollect> wrapper = new MybatisWrapper<GoodsCollect>()
                .orderByDesc("create_time");
        PageInfo<GoodsCollect> pageInfo = goodsCollectService.page(rowPage, wrapper);
        setModelAttribute(model, pageInfo);
        return "goodsCollect/list";
    }
    

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping("delete/{id}")
    public String del(@PathVariable Long id, RedirectAttributes attributes) {
        goodsCollectService.removeById(id);
        return redirect("/goodsCollect/list", "删除成功", attributes);
    }
    
   

    /**
     * 详情
     *
     * @param id
     * @param model
     * @return
     */
    @GetMapping("detail/{id}")
    public String detail(@PathVariable Long id, Model model) {
        GoodsCollect goodsCollect = goodsCollectService.getById(id);
        if (null == goodsCollect) {
            goodsCollect = new GoodsCollect();
        }
        model.addAttribute("goodsCollect", goodsCollect);
        return "goodsCollect/detail";
    }

    /**
     * 更新
     *
     * @param goodsCollect
     * @return
     */
    @RequestMapping("update")
    public String update(GoodsCollect goodsCollect, RedirectAttributes attributes) {
        goodsCollectService.saveOrUpdate(goodsCollect);
        return redirect("/goodsCollect/list", "操作成功", attributes);
    }

}


